"""精确C++类型的Python类型存根

提供精确的C++整数类型映射，允许Python代码中指定具体的C++整数类型。

支持两种定义方式：
1. class 定义（推荐用于类型）：语义清晰，IDE 支持更好
2. 赋值语句（适合真正的别名）：更简洁

使用 @mcpy_type_alias 注解来定义类型映射和 Protocol 支持：
- cpp_type: C++ 类型映射
- header: 头文件
- protocol: 满足的 Protocol

示例:
    from mc.types import int8_t, int32_t, int64_t

    def double(x: int32_t) -> int32_t:  # 满足 Integer 协议
        return x * 2
"""

from typing import TypeVar, Generic


# 字符类型（本质上是 8 位整数，满足 Integer 协议）
# @mcpy_type_alias: cpp_type=char, protocol=Integer
char = int  # type: ignore


# 有符号整数类型（满足 Integer 协议）
# @mcpy_type_alias: cpp_type=int8_t, header=<cstdint>, protocol=Integer
int8_t = int  # type: ignore


# @mcpy_type_alias: cpp_type=int16_t, header=<cstdint>, protocol=Integer
int16_t = int  # type: ignore


# @mcpy_type_alias: cpp_type=int32_t, header=<cstdint>, protocol=Integer
int32_t = int  # type: ignore


# @mcpy_type_alias: cpp_type=int64_t, header=<cstdint>, protocol=Integer
int64_t = int  # type: ignore


# 无符号整数类型（满足 Integer 协议）
# @mcpy_type_alias: cpp_type=uint8_t, header=<cstdint>, protocol=Integer
uint8_t = int  # type: ignore


# @mcpy_type_alias: cpp_type=uint16_t, header=<cstdint>, protocol=Integer
uint16_t = int  # type: ignore


# @mcpy_type_alias: cpp_type=uint32_t, header=<cstdint>, protocol=Integer
uint32_t = int  # type: ignore


# @mcpy_type_alias: cpp_type=uint64_t, header=<cstdint>, protocol=Integer
uint64_t = int  # type: ignore


# 特殊整数类型（满足 Integer 协议）
# @mcpy_type_alias: cpp_type=size_t, header=<cstddef>, protocol=Integer
size_t = int  # type: ignore


# @mcpy_type_alias: cpp_type=ptrdiff_t, header=<cstddef>, protocol=Integer
ptrdiff_t = int  # type: ignore

# @mcpy_type_alias: cpp_type=intptr_t, header=<cstdint>, protocol=Integer
intptr_t = int  # type: ignore

# @mcpy_type_alias: cpp_type=uintptr_t, header=<cstdint>, protocol=Integer
uintptr_t = int  # type: ignore


# 指针类型定义
class Pointer(Generic[TypeVar("T")]):
    """指针类型的泛型定义

    用于表示 C++ 指针类型，如 std::string*, int*, std::string** 等。
    在 Python 中作为类型注解使用，编译时会转换为对应的 C++ 指针类型。

    示例:
        char_ptr: Pointer[char] = ...  # 对应 C++ 的 char*
        argv: Pointer[Pointer[char]] = ...  # 对应 C++ 的 char**
        int_ptr: Pointer[int] = ...  # 对应 C++ 的 int*
    """

    pass


# 常用指针类型别名
# @mcpy_type_alias: cpp_type=char*
char_ptr = Pointer[char]  # char*

# @mcpy_type_alias: cpp_type=int*
int_ptr = Pointer[int]  # int*

# @mcpy_type_alias: cpp_type=void*
void_ptr = Pointer[None]  # void*

# @mcpy_type_alias: cpp_type=std::string*
str_ptr = Pointer[str]  # std::string*

# 导出所有类型
__all__ = [
    "int8_t",
    "int16_t",
    "int32_t",
    "int64_t",
    "uint8_t",
    "uint16_t",
    "uint32_t",
    "uint64_t",
    "size_t",
    "ptrdiff_t",
    "intptr_t",
    "uintptr_t",
    "Pointer",
    "char_ptr",
    "int_ptr",
    "void_ptr",
    "str_ptr",
]
